package com.ds.lens.data.service.dao.sql.provider;

import com.ds.lens.data.service.dao.entity.LensExternalEvent;
import org.apache.ibatis.jdbc.SQL;

public class LensExternalEventSqlProvider {

    public String insertSelective(LensExternalEvent record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("lens_external_event");

        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getMonitorId() != null) {
            sql.VALUES("monitor_id", "#{monitorId,jdbcType=BIGINT}");
        }

        if (record.getVersion() != null) {
            sql.VALUES("version", "#{version,jdbcType=INTEGER}");
        }

        if (record.getExternalEventType() != null) {
            sql.VALUES("external_event_type", "#{externalEventType,jdbcType=VARCHAR}");
        }

        if (record.getStartTime() != null) {
            sql.VALUES("start_time", "#{startTime,jdbcType=TIMESTAMP}");
        }

        if (record.getEndTime() != null) {
            sql.VALUES("end_time", "#{endTime,jdbcType=TIMESTAMP}");
        }

        if (record.getStatus() != null) {
            sql.VALUES("status", "#{status,jdbcType=SMALLINT}");
        }

        if (record.getReminders() != null) {
            sql.VALUES("reminders", "#{reminders,jdbcType=INTEGER}");
        }

        if (record.getLastReminderTime() != null) {
            sql.VALUES("last_reminder_time", "#{lastReminderTime,jdbcType=TIMESTAMP}");
        }

        if (record.getCreatedTime() != null) {
            sql.VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(LensExternalEvent record) {
        SQL sql = new SQL();
        sql.UPDATE("lens_external_event");

        if (record.getMonitorId() != null) {
            sql.SET("monitor_id = #{monitorId,jdbcType=BIGINT}");
        }

        if (record.getVersion() != null) {
            sql.SET("version = #{version,jdbcType=INTEGER}");
        }

        if (record.getExternalEventType() != null) {
            sql.SET("external_event_type = #{externalEventType,jdbcType=VARCHAR}");
        }

        if (record.getStartTime() != null) {
            sql.SET("start_time = #{startTime,jdbcType=TIMESTAMP}");
        }

        if (record.getEndTime() != null) {
            sql.SET("end_time = #{endTime,jdbcType=TIMESTAMP}");
        }

        if (record.getStatus() != null) {
            sql.SET("status = #{status,jdbcType=SMALLINT}");
        }

        if (record.getReminders() != null) {
            sql.SET("reminders = #{reminders,jdbcType=INTEGER}");
        }
        if (record.getLastReminderTime() != null) {
            sql.SET("last_reminder_time = #{lastReminderTime,jdbcType=TIMESTAMP}");
        }

        if (record.getCreatedTime() != null) {
            sql.SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }

        sql.WHERE("id = #{id,jdbcType=BIGINT}");

        return sql.toString();
    }
}
